package com.Dao.Imp;
import com.Dao.InsertInfoDao;
import com.Utils.C3P0Utils;
import com.pojo.Reply;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.dbutils.QueryRunner;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
@Service
@Slf4j
public class InsertInfoDaoImp implements InsertInfoDao {
    @Override
    public void insertInfo(String aliasName, String profile, String userName, String wechat) throws SQLException {
        QueryRunner queryRunner=new QueryRunner(C3P0Utils.getDataSource());
        String sql="insert into authorTemporary(aliasname,profile,username,wechat)values(?,?,?,?)";
        queryRunner.update(sql,aliasName,profile,userName,wechat);
    }
    @Override
    public void insertComment(String username, int bookId, String comment,String timeStamp) throws SQLException {
        QueryRunner queryRunner=new QueryRunner(C3P0Utils.getDataSource());
        String sql="insert into remark(bookId,userAlias,comment,remarkTime)values(?,?,?,?)";
        queryRunner.update(sql,bookId,username,comment,timeStamp);
    }

    @Override
    public void insertReply(Reply reply) throws SQLException {
        QueryRunner queryRunner=new QueryRunner(C3P0Utils.getDataSource());
        String sql="insert into reply(remarkId,bookId,username,replyText,replyTime)values(?,?,?,?,?)";
        queryRunner.update(sql,reply.getRemarkId(),reply.getBookId(),reply.getUsername(),reply.getReplyText(),reply.getReplyTime());
    }
}
